package com.cardvalue.sys.tool;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * 获取应用的版本号
 * Created by cardvalue on 2016/3/30.
 */
public class VersionUtil {

    public static final String TAG=VersionUtil.class.getSimpleName();

    private VersionUtil(){
        throw  new UnsupportedOperationException(TAG+"无需实例化");
    }

    /**
     * 获取版本号
     * @param context
     * @return
     */
    public static  String  getVersionName(Context context){
        PackageInfo pi=null;
        try {
            pi=context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return pi.versionName;
    }

}
